var mysql = require('mysql');

var sqlQuery = (sql, params) => {
    return new Promise((resolve, reject) => {
        var connection = mysql.createConnection({
            host: 'localhost',
            user: 'root',
            password: '123456',
            database: 'check'
        })
        connection.connect(err => {
            if (err) {
                console.log('数据库连接失败');
                reject(err);
                throw err;
            }
        })
        connection.query(sql, params, function (err, results) {
            if (err) {
                console.log('数据操做失败');
                reject(err);
                return;
            }
            resolve(results);
        })
        connection.end()
    })
}

exports.sqlQuery = sqlQuery;